﻿<UserControl x:Class="Cyclops.MainApplication.View.LoginView" 
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:Controls="clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit.Extended" 
             xmlns:ViewModel="clr-namespace:Cyclops.MainApplication.ViewModel" 
             xmlns:ValueConverters="clr-namespace:Cyclops.MainApplication.ValueConverters" 
             xmlns:Localization1="clr-namespace:Cyclops.MainApplication.Localization;assembly=Cyclops.MainApplication.Localization"
             mc:Ignorable="d" Background="Transparent" d:DesignHeight="478" d:DesignWidth="739" UseLayoutRounding="True"
             FocusManager.FocusedElement="{Binding ElementName=userName}" Loaded="UserControlLoaded"
             TextOptions.TextFormattingMode="Display" TextOptions.TextRenderingMode="ClearType">
    <UserControl.DataContext>
        <ViewModel:LoginViewModel />
    </UserControl.DataContext>

    <UserControl.Resources>
        <ValueConverters:IsNullToCollapsedValueConverter x:Key="isNullConverter"/>
        <Style x:Key="FieldNameStyle">
            <Setter Property="TextBlock.VerticalAlignment" Value="Center"/>
            <Setter Property="TextBlock.HorizontalAlignment" Value="Right"/>
            <Setter Property="TextBlock.Margin" Value="0,0,10,0"/>
            <Setter Property="TextBlock.Foreground" Value="White"/>
            <Setter Property="TextBlock.FontSize" Value="15"/>
        </Style>
        <Style x:Key="FieldValueStyle">
            <Setter Property="TextBox.VerticalAlignment" Value="Center"/>
            <Setter Property="TextBox.HorizontalAlignment" Value="Left"/>
            <Setter Property="TextBox.Margin" Value="3"/>
            <Setter Property="TextBox.FontSize" Value="14"/>
            <Setter Property="TextBox.SelectionBrush" Value="#FF0B5299"/>
            <Setter Property="TextBox.Height" Value="26"/>
            <Setter Property="TextBox.Width" Value="170"/>
        </Style>
        <Style x:Key="ButtonStyle" TargetType="{x:Type Button}">
            <Setter Property="Width" Value="100"/>
            <Setter Property="Height" Value="26"/>
            <Setter Property="FontSize" Value="14"/>
        </Style>
    </UserControl.Resources>


    <Controls:BusyIndicator x:Name="busyIndicator" 
                            BusyContent="{Binding Path=Common.PleaseWait, Source={StaticResource ResourceWrapper}}" 
                            IsBusy="{Binding IsBusy}" Focusable="False">
        <Grid x:Name="LayoutRoot">

            <Grid VerticalAlignment="Center" >
                <Grid.RowDefinitions>
                    <RowDefinition Height="70" />
                    <RowDefinition />
                    <RowDefinition Height="70" />
                </Grid.RowDefinitions>
                <TextBlock TextOptions.TextFormattingMode="Ideal" Text="Cyclops Chat" VerticalAlignment="Top" FontWeight="Bold" Foreground="White" FontSize="48" Margin="10,-5,0,0">
					<TextBlock.Effect>
						<DropShadowEffect ShadowDepth="0" BlurRadius="7"/>
					</TextBlock.Effect>
                </TextBlock>
                <TextBlock Text="1.0.9 RC2" VerticalAlignment="Top" FontWeight="Bold" Foreground="White" FontSize="18.667" Margin="312,8,-312,0"/>
                <TextBlock Grid.Row="2" Foreground="#FFFF7E7E" Text="{Binding ErrorMessage}" FontSize="15"
                       Visibility="{Binding ErrorMessage, Converter={StaticResource isNullConverter}}"
				       TextWrapping="Wrap" Margin="5,5,5,0"/>


                <Grid Grid.Row="1" Height="Auto" Background="#3B000000" VerticalAlignment="Top" Margin="0,0,0,0">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="160" />
                        <ColumnDefinition />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="30"/>
                        <RowDefinition Height="30"/>
                        <RowDefinition Height="30"/>
                        <RowDefinition MinHeight="38"/>
                    </Grid.RowDefinitions>
                    <TextBlock Grid.Row="1" Text="{Binding Path=Login.UserName, Source={StaticResource ResourceWrapper}}" Style="{StaticResource FieldNameStyle}"/>
                    <TextBlock Grid.Row="2" Text="{Binding Path=Login.Password, Source={StaticResource ResourceWrapper}}" Style="{StaticResource FieldNameStyle}"/>
                    <Button Grid.Row="2" Grid.Column="1" HorizontalAlignment="Left" Style="{StaticResource ButtonStyle}" Margin="178,0,0,0" Command="{Binding Authenticate}" CommandParameter="{Binding ElementName=passwordBox}" 
                            IsDefault="True" Content="{Binding Path=Login.Connect, Source={StaticResource ResourceWrapper}}" />
                    <Button Grid.Row="2" Grid.Column="1" HorizontalAlignment="Left" Style="{StaticResource ButtonStyle}" Command="{Binding Register}" CommandParameter="{Binding ElementName=passwordBox}" 
                            Content="{Binding Path=Login.RegisterAccount, Source={StaticResource ResourceWrapper}}" Margin="282,2,0,2" Width="155"/>
                    <Expander Grid.Row="3" Grid.Column="1" x:Name="expander" Header="{Binding Path=Login.AdvancedSettings, Source={StaticResource ResourceWrapper}}" 
							  VerticalAlignment="Top" Foreground="White" FontSize="15" Margin="3,4,0,6" >
                        <Grid Background="#2E000000" Margin="-165,0,0,0">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="162" />
                                <ColumnDefinition />
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="10" />
                                <RowDefinition Height="30" />
                                <RowDefinition Height="30" />
                                <RowDefinition Height="25" />
                            </Grid.RowDefinitions>
                            <CheckBox Grid.Row="1" Style="{StaticResource FieldNameStyle}" IsChecked="{Binding AutoLogin, Mode=TwoWay}" Content="{Binding Path=Login.AutoLogin, Source={StaticResource ResourceWrapper}}" HorizontalAlignment="Left" Margin="3,6,0,0" Grid.Column="1" VerticalAlignment="Top"/>
                            <TextBlock Grid.Row="2" Style="{StaticResource FieldNameStyle}" Text="{Binding Path=Login.Server, Source={StaticResource ResourceWrapper}}"/>
                            <TextBox Grid.Row="2" Grid.Column="1" Text="{Binding Server, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource FieldValueStyle}" Margin="3,3,0,3" Width="181"/>
                        </Grid>
                    </Expander>
                    <TextBox Grid.Row="1" Grid.Column="1" x:Name="userName" Text="{Binding Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource FieldValueStyle}"/>
                    <PasswordBox Grid.Row="2" Grid.Column="1" x:Name="passwordBox" Style="{StaticResource FieldValueStyle}"/>
                </Grid>
            </Grid>
            <StackPanel Grid.Row="0" Height="21" Orientation="Horizontal" VerticalAlignment="Top" Margin="5">
                <!--<TextBlock Foreground="White" Text="Language: " VerticalAlignment="Center"/>-->
                <ComboBox Margin="5,0,0,0" Width="75"
                          ItemsSource="{Binding Source={x:Static Localization1:LocalizationManager.Instance}, Path=Languages}"
                          SelectedItem="{Binding Source={x:Static Localization1:LocalizationManager.Instance}, Path=SelectedLanguage, Mode=TwoWay}" />
            </StackPanel>
        </Grid>
    </Controls:BusyIndicator>
</UserControl>